using System;
using Servlets.Api;
using Servlets.Attributes;

namespace TestServlets
{
	[Servlet]
	public class TheServlet
	{
		[GetMethod("/")]
		[GetMethod("/index")]
		public void Index(IRequest request, IResponse response)  {
			response.OutputStream.WriteLine("hello from /index");
			request.Attributes["Hi"] = "this is stored";
			request.RequestDispatcher.Forward("/forward");
		}
		
		[GetMethod("/forward")]
		public void Forwarded(IRequest request, IResponse response) {
			response.OutputStream.WriteLine("hello from /forward");
			string cheese;
			try {
				cheese = (string)request.Attributes["Hi"];
			} catch (Exception) {
				cheese = "There was nothing in Attributes[Hi]";
			}
			response.OutputStream.WriteLine(cheese);
		}
		
		[GetMethod("/get")]
		public void Get(IRequest request, IResponse response) {
			request.Attributes["name"] = "Joel";
			request.RequestDispatcher.Forward("/get.milk");
		}
		
		[GetMethod("/params/$id$/$name$")]
		public void UploadMethod(IRequest request, IResponse response, string id, string name) {
			response.OutputStream.WriteLine("id: "+id+"<br/>");
			response.OutputStream.WriteLine("name: "+name+"<br/>");
		}
	}
}
